<?php
include_once ("koneksi.php");

class ModelTestimoni {

	public function __construct (){
		$this-> koneksi = new Koneksi();
	} //<!--end of __construct-->
	
	public function addTestimoni($id_user, $nama_pengirim, $isitestimoni, $judultestimoni)
	{
		$this->koneksi->_connect();
		$query = mysql_query("INSERT INTO `testimoni` (id_testimoni, id_user, nama_pengirim, isitestimoni, judultestimoni) 
		VALUES ('', '$id_user', '$nama_pengirim', '$isitestimoni', '$judultestimoni');");
		$this->koneksi->_close();
		return true;
	}//<!--end of addtestimoni-->
	
	public function getTestimoni()
	{
		$this->koneksi->_connect();
		$query = "select * from testimoni";
		
		$result = mysql_query($query);
		while ($data = mysql_fetch_array($result)) {
			$array[$data['ID_TESTIMONI']]=new Testimoni($data['ID_TESTIMONI'], $data['ID_USER'], $data['NAMA_PENGIRIM'], $data['ISITESTIMONI'], $data['JUDULTESTIMONI']);
		}
		$this->koneksi->_close();
		if (!empty($array))
		{
			return $array;
		}
	}//<!--end of getTestiomoni-->
	
	public function getTestimoniUser($id_user)
	{
		$this->koneksi->_connect();
		$query = mysql_query("select * from testimoni where id_user='$id_user'");
		while ($data = mysql_fetch_array($query)) {
			$array[$data['ID_TESTIMONI']]=new Testimoni($data['ID_TESTIMONI'], $data['ID_USER'], $data['NAMA_PENGIRIM'], $data['ISITESTIMONI'], $data['JUDULTESTIMONI']);
		}
		$this->koneksi->_close();
		if (!empty($array))
		{
			return $array;
		}
	}//<!--end of getTestiomoniUser-->
	
	public function  deleteTestimoni($id_testimoni){
		$this->koneksi->_connect();
		$query = mysql_query("DELETE FROM `testimoni` WHERE id_testimoni = '$id_testimoni';");	
		$this->koneksi->_close();
		return true;
	}//<!--end of deleteTestiomoni-->
}
?>

<?php

class Testimoni {
	public $id_testimoni;
	public $id_user;
	public $nama_pengirim;
	public $isitestimoni;
	public $judultestimoni;
	
	public function __construct($id_testimoni, $id_user, $nama_pengirim, $isitestimoni, $judultestimoni)  
    {  
        $this->id_testimoni = $id_testimoni;
	    $this->id_user = $id_user;
	    $this->nama_pengirim = $nama_pengirim;
		$this->isitestimoni = $isitestimoni;
		$this->judultestimoni = $judultestimoni;
    } 
}
?>